package io.openmessaging.storage.dledger.client;

import io.openmessaging.storage.dledger.protocol.DLedgerClientProtocol;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class DLedgerClientRpcService implements DLedgerClientProtocol {

    private Map<String, String> peerMap = new ConcurrentHashMap<>();

    public void updatePeers(String peers) {
        for (String peerInfo : peers.split(";")) {
            String nodeId = peerInfo.split("-")[0];
            peerMap.put(nodeId, peerInfo.substring(nodeId.length() + 1));
        }
    }

    public void updatePeers(Map<String, String> peers) {
        peerMap.putAll(peers);
    }

    public String getPeerAddr(String id) {
        return peerMap.get(id);
    }

    public abstract void startup();

    public abstract void shutdown();
}
